package com.ruoyi.recipes.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.recipes.domain.RecipeSteps;
import com.ruoyi.recipes.service.IRecipeStepsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 制作步骤Controller
 * 
 * @author syy
 * @date 2025-08-14
 */
@RestController
@RequestMapping("/recipes/steps")
public class RecipeStepsController extends BaseController
{
    @Autowired
    private IRecipeStepsService recipeStepsService;

    /**
     * 查询制作步骤列表
     */
    @PreAuthorize("@ss.hasPermi('recipes:steps:list')")
    @GetMapping("/list")
    public TableDataInfo list(RecipeSteps recipeSteps)
    {
        startPage();
        List<RecipeSteps> list = recipeStepsService.selectRecipeStepsList(recipeSteps);
        return getDataTable(list);
    }

    /**
     * 导出制作步骤列表
     */
    @PreAuthorize("@ss.hasPermi('recipes:steps:export')")
    @Log(title = "制作步骤", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RecipeSteps recipeSteps)
    {
        List<RecipeSteps> list = recipeStepsService.selectRecipeStepsList(recipeSteps);
        ExcelUtil<RecipeSteps> util = new ExcelUtil<RecipeSteps>(RecipeSteps.class);
        util.exportExcel(response, list, "制作步骤数据");
    }

    /**
     * 获取制作步骤详细信息
     */
    @PreAuthorize("@ss.hasPermi('recipes:steps:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(recipeStepsService.selectRecipeStepsById(id));
    }

    /**
     * 新增制作步骤
     */
    @PreAuthorize("@ss.hasPermi('recipes:steps:add')")
    @Log(title = "制作步骤", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RecipeSteps recipeSteps)
    {
        return toAjax(recipeStepsService.insertRecipeSteps(recipeSteps));
    }

    /**
     * 修改制作步骤
     */
    @PreAuthorize("@ss.hasPermi('recipes:steps:edit')")
    @Log(title = "制作步骤", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RecipeSteps recipeSteps)
    {
        return toAjax(recipeStepsService.updateRecipeSteps(recipeSteps));
    }

    /**
     * 删除制作步骤
     */
    @PreAuthorize("@ss.hasPermi('recipes:steps:remove')")
    @Log(title = "制作步骤", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(recipeStepsService.deleteRecipeStepsByIds(ids));
    }
}
